<?php
namespace Components\Staff\Sha;

class Logic {
  protected function getPaginate($builder, $limit, $page) {
    return ['code' => 0, 'pager'=>(new \Phalcon\Paginator\Adapter\QueryBuilder([
      'builder' => $builder,
      'limit' => $limit,
      'page' => $page
    ])) -> getPaginate()];
  }

  public function pager($limit, $page) {
    $builder = (new \Phalcon\Mvc\Model\Query\Builder())
      -> from([
        'staff' => __NAMESPACE__ . '\\Model',
        'staff_acl_roles' => __NAMESPACE__ . '\\ACL\Roles\\Model',
      ])
			-> where('staff.roles_id = staff_acl_roles.id')
      -> orderBy('staff.id DESC');

    return $this -> getPaginate($builder, $limit, $page);
  }
}
